<?php
namespace app\admin\controller;

use think\Db;
use think\Session;
use think\Request;
use think\Controller;
class Outexcel extends Controller
{
    //导出领券记录
    public function downExcelExchange(){
        $where = [];
        $keyword = $this->request->param('keyword');
        if($keyword){
            $where[] = ['e.username|e.mobile|e.cardHyNo|e.cardLevel','like','%'.$keyword.'%'];
        }
    	$begin = $this->request->param('begin');
        $end = $this->request->param('end');
        if($begin || $end){
            $where[] = search_time('gettime',$begin,$end);
        }
    
        $title = '优惠券领取记录'.date("Ymd");
        $field  = ['id','手机号','姓名','卡号','卡级','券名称','促销单号','扣减积分','赠券号','兑换时间'];
        
        $record = Db::name('exchange')
        	->alias('e')
        	->join('coupon c','c.id = e.coupon_id')
        	->where($where)
            ->field("e.id,e.mobile,e.userName,e.cardHyNo,e.cardLevel,c.coupon_name,c.promotion_num,c.point,e.certino,e.gettime")
            ->order('id desc')
            ->select();
//      dump($record);
        (new Common())->downExcel('券领取记录',$field,$record,$title);
    }
    //导出日志
    public function downExcelApilog(){
        $where = [];
        $keyword = $this->request->param('keyword');
        if($keyword){
            $where[] = ['api|status|message|inParam|outParam','like','%'.$keyword.'%'];
        }
    	$begin = $this->request->param('begin');
        $end = $this->request->param('end');
        if($begin || $end){
            $where[] = search_time('createtime',$begin,$end);
        }
    	
        $title = '店庆接口请求日志'.date("Ymd");
        $field  = ['id','接口名','请求参数','返回json','返回xml','结果','调用时间'];
        
        $record = Db::name('apilog')
        	->where($where)
            ->field("id,api,inParam,outParam,message,status,createtime")
            ->order('id desc')
            ->select();
//      dump($record);
        (new Common())->downExcel('店庆接口请求日志',$field,$record,$title);
    }
}
